package com.wusiwei.controller;

import com.wusiwei.common.Result;
import com.wusiwei.service.InvoiceStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 发票统计控制器
 */
@RestController
@RequestMapping("/api/invoices/statistics")
@Tag(name = "发票统计", description = "发票统计相关的API接口")
@RequiredArgsConstructor
@Slf4j
public class InvoiceStatisticsController {

    private final InvoiceStatisticsService invoiceStatisticsService;

    /**
     * 获取发票总体统计信息
     */
    @Operation(summary = "获取发票总体统计信息", description = "包括总数量、总金额、总税额等")
    @GetMapping("/overall")
    public Result<Map<String, Object>> getOverallStatistics() {
        return invoiceStatisticsService.getOverallStatistics();
    }

    /**
     * 按供应商统计发票
     */
    @Operation(summary = "按供应商统计发票", description = "按供应商分组统计发票数量和金额")
    @GetMapping("/supplier")
    public Result<Map<String, Object>> getStatisticsBySupplier() {
        return invoiceStatisticsService.getStatisticsBySupplier();
    }

    /**
     * 按发票类别统计
     */
    @Operation(summary = "按发票类别统计", description = "按发票类别分组统计数量和金额")
    @GetMapping("/category")
    public Result<Map<String, Object>> getStatisticsByCategory() {
        return invoiceStatisticsService.getStatisticsByCategory();
    }

    /**
     * 获取月度发票金额趋势
     */
    @Operation(summary = "获取月度发票金额趋势", description = "获取指定年份的月度发票金额趋势")
    @GetMapping("/trend/monthly")
    public Result<Map<String, Object>> getMonthlyTrend(
            @Parameter(description = "年份，如不指定则默认当前年") @RequestParam(required = false) Integer year) {
        return invoiceStatisticsService.getMonthlyTrend(year);
    }
} 